home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / selection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-11-14  |  6.0 KB  |  189 lines

  1. /*
  2. For general Scribus (>=1.3.2) copyright and licensing information please refer
  3. to the COPYING file provided with the program. Following this notice may exist
  4. a copyright and/or license notice that predates the release of Scribus 1.3.2
  5. for which a new license (GPL+exception) is in place.
  6. */
  7. /***************************************************************************
  8.     copyright            : (C) 2005 by Craig Bradney
  9.     email                : cbradney@zip.com.au
  10. ***************************************************************************/
  11.  
  12. /***************************************************************************
  13. *                                                                         *
  14. *   This program is free software; you can redistribute it and/or modify  *
  15. *   it under the terms of the GNU General Public License as published by  *
  16. *   the Free Software Foundation; either version 2 of the License, or     *
  17. *   (at your option) any later version.                                   *
  18. *                                                                         *
  19. ***************************************************************************/
  20. #ifndef SELECTION_H
  21. #define SELECTION_H
  22.  
  23. #include <QList>
  24. #include <QMap>
  25. #include <QObject>
  26. #include <QPointer>
  27.  
  28. #include "pageitem.h"
  29. #include "scribusapi.h"
  30.  
  31. typedef QList< QPointer<PageItem> > SelectionList;
  32.  
  33. class SCRIBUS_API Selection : public QObject
  34. {
  35.     Q_OBJECT
  36.     public:
  37.         /**
  38.          * \brief Create an empty selection that is not a GUI selection
  39.          * @param  parent QObject
  40.          */
  41.         explicit Selection(QObject* parent);   // otherwise implicit conversion Selection* -> Selection& is possible
  42.         /**
  43.          * \brief Create an empty selection that may be a GUI selection
  44.          * @param  parent QObject
  45.          * @param  guiSelection If the selection is to be a GUI selection
  46.          */
  47.         Selection(QObject* parent, bool guiSelection);
  48.         /**
  49.          * \brief Copy a selection
  50.          * \note We are leaving the connections of the items in place
  51.          * and the isGUISelection set in the copy. We cannot disconnect them
  52.          * as they may be connected via the main GUI selection.
  53.          * @param  other selection
  54.          */
  55.         Selection(const Selection& other);
  56.         Selection& operator=( const Selection & );
  57.         ~Selection();
  58.  
  59.         /**
  60.          * \brief Copy the selection of items from one selection to another
  61.          */
  62.         void copy(Selection& other, bool emptyOther);
  63.         
  64.         bool connectItemToGUI();
  65.         /**
  66.          * \brief Disconnect all items from the GUI slots. 
  67.          * This should not really be necessary if all things are going ok
  68.          * except for within the clearAll function.
  69.          * @return bool true on success
  70.          */
  71.         bool disconnectAllItemsFromGUI();
  72.         /**
  73.          * @brief Add an item to the selection. 
  74.          * If its added to a GUI selection selection and its item 0, its connected to the GUI too
  75.          * @param item Item to add
  76.          * @param ignoreGUI Dont connect Item To GUI even if this is a GUI selection
  77.          * @return If the item was added
  78.          */
  79.         bool addItem(PageItem *item, bool ignoreGUI=false);
  80.         /**
  81.          * @brief Prepend an item to the selection. 
  82.          * If its added to a GUI selection selection and its item 0, its connected to the GUI too
  83.          * @param item Item to add
  84.          * @param doEmit call emitAllToGUI()
  85.          * @return If the item was added
  86.          */
  87.         bool prependItem(PageItem *item, bool doEmit=true);
  88.  
  89.         bool containsItem(PageItem *item) const { return m_SelList.contains(item); }
  90.         /**
  91.          * \brief Unused
  92.          */
  93.         bool addGroup();
  94.         /**
  95.          * \brief Remove an item from list
  96.          * @param item page item
  97.          */
  98.         bool removeItem(PageItem *item);
  99.         /**
  100.          * \brief Remove the first item from the list
  101.          * @return If the remove was successful
  102.          */
  103.         bool removeFirst();
  104.         /**
  105.          * \brief Unused
  106.          */
  107.         bool removeGroup();
  108.         /**
  109.          * \brief Remove an item from list listNumber and return a pointer to it
  110.          * @param itemIndex Index of the item in the list
  111.          * @return Item
  112.          */
  113.         PageItem* takeItem(int itemIndex);
  114.         /**
  115.          * \brief Find an item from the selection and return an index to it
  116.          * @param item Item pointer to find in the list
  117.          * @return Item
  118.          */
  119.         int findItem(PageItem *item) const { return m_SelList.indexOf(item); }
  120.         /**
  121.          * \brief Return the count of the selection
  122.          */
  123.         int count() const { return m_SelList.count(); }
  124.         /**
  125.          * \brief Check if the selection is empty.
  126.          */
  127.         bool isEmpty() const { return m_SelList.count()==0; }
  128.         /**
  129.          * \brief Clear a list
  130.          */
  131.         bool clear();
  132.         /**
  133.          * \brief See if the first selected item is "me", usually called from an item object with "this".
  134.          * @param item PageItem reference
  135.          */
  136.         bool primarySelectionIs(const PageItem* item) const { return (!m_SelList.isEmpty() && (item==m_SelList.first())); }
  137.         PageItem *itemAt(int index=0) { return itemAt_(index); }
  138.         const PageItem *itemAt(int index=0) const { return const_cast<Selection*>(this)->itemAt_(index); }
  139.         QStringList getSelectedItemsByName() const;
  140.         bool isMultipleSelection() const { return m_hasGroupSelection; }
  141.         bool isGUISelection() const { return m_isGUISelection; }
  142.         double width() const;
  143.         double height() const;
  144.         //set the group rectangle properties
  145.         void setGroupRect();
  146.         void getGroupRect(double *x, double *y, double *w, double *h);
  147.         void getVisualGroupRect(double *x, double *y, double *w, double *h);
  148.         //!\brief Test to see if all items in the selection are the same typedef
  149.         bool itemsAreSameType() const;
  150.  
  151.         /**
  152.          * \brief get the layer ID of items in the selection
  153.          * @return the layer ID or -1 if items do not belong to the same layer
  154.          */
  155.         int objectsLayer(void) const;
  156.  
  157.         bool signalsDelayed(void);
  158.         void delaySignalsOn(void);
  159.         void delaySignalsOff(void);
  160.         
  161.     protected:
  162.         PageItem *itemAt_(int index=0);
  163.         SelectionList m_SelList;
  164.         bool m_hasGroupSelection;
  165.         bool m_isGUISelection;
  166.         double groupX;
  167.         double groupY;
  168.         double groupW;
  169.         double groupH;
  170.         
  171.         double visualGX;
  172.         double visualGY;
  173.         double visualGW;
  174.         double visualGH;
  175.  
  176.         int  m_delaySignals;
  177.         bool m_sigSelectionChanged;
  178.         bool m_sigSelectionIsMultiple;
  179.  
  180.         void sendSignals(bool guiConnect = true);
  181.         
  182.     signals:
  183.         void selectionIsMultiple(bool);
  184.         void empty();
  185.         void selectionChanged();
  186. };
  187.  
  188. #endif
  189.